﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;

namespace Client.ViewModel
{
    public class ResultViewModel : BaseViewModel
    {
        #region Bound properties

        private int _score;
        public int Score
        {
            get { return _score; }
            set
            {
                _score = value;
                OnPropertyChanged("Score");
            }
        }
        
        private int _totalScore;
        public int TotalScore
        {
            get { return _totalScore; }
            set
            {
                _totalScore = value;
                OnPropertyChanged("TotalScore");
            }
        }

        private string _fullName;
        public string FullName {
            get { return _fullName; }
            set
            {
                _fullName = value;
                Regex rgx = new Regex(@"^[A-Za-z ]+$");
                if (String.IsNullOrEmpty(value) || !rgx.IsMatch(value))
                {
                    throw new ApplicationException("A név kitöltése kötelező, és csak betűket és szóközt tartalmazhat!");
                }
            }
        }
        #endregion

        #region Other variables

        private int _quizId;

        #endregion

        public ResultViewModel(int totalScore,int score,int quizId)
        {
            TotalScore = totalScore;
            Score = score;
            _quizId = quizId;
        }

        public void Save()
        {
            try
            {
                using (var srv = new QuizService.QuizServiceClient())
                {
                    srv.SaveScore(FullName, Score, _quizId);
                }
            }
            catch
            {
                MessageBox.Show("Hát ez nem sikerült, bocsi.");
            }
        }
    }
}
